package cn.iocoder.yudao.module.ordering.dal.mysql.food;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ordering.controller.admin.food.vo.FoodPageReqVO;
import cn.iocoder.yudao.module.ordering.dal.dataobject.food.FoodDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 订餐-餐品信息 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface FoodMapper extends BaseMapperX<FoodDO> {

    default PageResult<FoodDO> selectPage(FoodPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FoodDO>()
                .likeIfPresent(FoodDO::getName, reqVO.getName())
                .eqIfPresent(FoodDO::getType, reqVO.getType())
                .eqIfPresent(FoodDO::getStatus, reqVO.getStatus())
                .geIfPresent(FoodDO::getDateStart,
                        reqVO.getDateQuery() != null &&reqVO.getDateQuery().length > 2 ?
                        reqVO.getDateQuery()[1] : null)
                .leIfPresent(FoodDO::getDateEnd,
                        reqVO.getDateQuery() != null &&reqVO.getDateQuery().length > 2 ?
                        reqVO.getDateQuery()[0] : null)
                .orderByDesc(FoodDO::getId));
    }

    /**
     * 查询员工订餐列表
     *
     * @param params
     * @return List<FoodDO>
     * @date 2024/7/26 17:02
     * @author lililiang
     */
    default List<FoodDO> selectListCommon(FoodDO params){
        return selectList(new LambdaQueryWrapperX<FoodDO>()
                .gtIfPresent(FoodDO::getDateEnd, params.getOrderDate())
                .leIfPresent(FoodDO::getDateStart, params.getOrderDate())
                .eqIfPresent(FoodDO::getStatus, params.getStatus())
                .inIfPresent(FoodDO::getId, params.getIds())
                .orderByAscIfPresent(FoodDO::getType, params.getTypeOrderByAsc())
        );
    }
}
